;(function(){
	var centerObj= new Object();
	centerObj.w=1000;
	centerObj.h=765;
	centerObj.canvas=document.createElement("canvas");
	centerObj.ele=document.getElementById("demo");
	centerObj.maxBox=new HGAME.canvas({
	    w:centerObj.w,
	    h:centerObj.h
	});
	centerObj.loedSource=new HGAME.source();
	centerObj.animate04=new HGAME.animate();
	centerObj.animate02=new HGAME.animate({time:90});
	centerObj.addNumTime=30;
	centerObj.animate02.action=function(){
	    var i = 0,q=0;
	    for(i = 0;i<centerObj.fishArr.length;i++){
	        if(typeof centerObj.fishArr[i]=="undefined")continue;
	        if(!centerObj.fishArr[i].method02){continue}
	        for(q=0;q<centerObj.fishArr[i].method02.length;q++){
	            if(centerObj.fishArr[i].method02[q].centerObj){
	                centerObj.fishArr[i][centerObj.fishArr[i].method02[q].name]&&centerObj.fishArr[i][centerObj.fishArr[i].method02[q].name](centerObj);
	            }else{
	                centerObj.fishArr[i][centerObj.fishArr[i].method02[q].name]&&centerObj.fishArr[i][centerObj.fishArr[i].method02[q].name]();
	            }
	            if(typeof centerObj.fishArr[i]=="undefined")break;
	        }
	    }

	    for(i=0;i<centerObj.bulletArr.length;i++){
	        centerObj.bulletArr[i].changeImageInfo();
	    }
	};
	centerObj.animate03=new HGAME.animate({time:60});
	centerObj.animate03.action=function(){
	    for(var i=0;i<centerObj.goldArr.length;i++){
	        centerObj.goldArr[i].changeImgInfo();
	        centerObj.goldArr[i].changeXYInfo(centerObj);
	    }
	};
	
	centerObj.imgNum=new Image();
	centerObj.imgNum2=new Image();
	centerObj.imgGlod=new Image();
	centerObj.imgGlod2=new Image();
	centerObj.imgInfoInterface={};
	centerObj.rectInfoInterface={};
	centerObj.loedSource.loadCall=function(a,b){
	    var txt = centerObj.maxBox.txt;
	    txt.beginPath();
	    txt.clearRect(0,0,centerObj.w,centerObj.h);
	    txt.font="normal normal 20px/24px arial";
	    txt.textBaseline="middle";
	    txt.textAlign="center";
	    txt.fillStyle="#000000";
	    txt.fillRect(0,0,centerObj.w,centerObj.h);
	    txt.fillStyle="#ffffff";
	    txt.fillText("加载资源:"+a+"/"+b,centerObj.w/2,centerObj.h/2);
	    txt.closePath();
	};

	centerObj.loedSource.loadedSource([
	    "img/Interface/cannon_minus.png",
	    "img/Interface/startbg.jpg",
	    "img/pwoerPd/JadePerch_IN_Particles_01-hd.png",
	    "img/pwoerPd/JadePerch_IN_Particles_02-hd.png",
	    "img/pwoerPd/JadePerch_IN_Particles_03-hd.png",
	    "img/pwoerPd/JadePerch_IN_Particles_04-hd.png",
	    "img/pwoerPd/JadePerch_IN_Particles_05-hd.png",
	    "img/pwoerPd/JadePerch_IN_Particles_06-hd.png",
	    "img/pwoerPd/JadePerch_IN_Particles_07-hd.png",
	    "img/pwoerPd/JadePerch_IN_Particles_08-hd.png",
	    "img/pwoerPd/JadePerch_Particles_01-hd.png",
	    "img/pwoerPd/JadePerch_Particles_02-hd.png",
	    "img/pwoerPd/JadePerch_Particles_03-hd.png",
	    "img/pwoerPd/JadePerch_Particles_04-hd.png",
	    "img/pwoerPd/JadePerch_Particles_05-hd.png",
	    "img/Interface/bg1.jpg",
	    "img/Interface/b.jpg",
	    "img/Interface/energy-bar.png",
	    "img/Interface/back.png",
	    "img/Interface/jn1.png",
	    "img/Interface/c.jpg",
	    "img/Interface/d.jpg",
	    "img/Interface/e.jpg",
	    "img/Interface/game_bg_2_hd.jpg",
	    "img/Interface/cannon_minus_down.png",
	    "img/Interface/cannon_plus.png",
	    "img/Interface/login.png",
	    "img/Interface/cannon_plus_down.png",
	    "img/glod/coinText.png",//黄色的数字
	    "img/glod/number_black.png",//白色的数字
	    "img/glod/coinAni1.png",//白色的金币
	    "img/glod/coinAni2.png",//黄色的金币
	    "img/Interface/bottom-bar.png",
	    "img/bullet/cannon1.png",
	    "img/bullet/cannon2.png",
	    "img/bullet/cannon3.png",
	    "img/bullet/cannon4.png",
	    "img/bullet/cannon5.png",
	    "img/bullet/cannon6.png",
	    "img/bullet/cannon7.png",
	    "img/bullet/bullet1.png",
	    "img/bullet/bullet2.png",
	    "img/bullet/bullet3.png",
	    "img/bullet/bullet4.png",
	    "img/bullet/bullet5.png",
	    "img/bullet/bullet6.png",
	    "img/bullet/bullet7.png",
	    "img/bullet/web1s.png",
	    "img/bullet/web2s.png",
	    "img/bullet/web3s.png",
	    "img/bullet/web4s.png",
	    "img/bullet/web5.png",
	    "img/bullet/web6s.png",
	    "img/bullet/web7s.png"
	],function(){
	    centerObj.imgNum.src= "img/glod/coinText.png";
	    centerObj.imgNum2.src= "img/glod/number_black.png";
	    centerObj.imgGlod.src= "img/glod/coinAni1.png";
	    centerObj.imgGlod2.src= "img/glod/coinAni2.png";
	    centerObj.imgInfoInterface.back=METHOD.createImg("img/Interface/back.png");

	    startUI(centerObj.maxBox.txt);
	    centerObj.pt = new HGAME.Object2D({
	        img:METHOD.createImg("img/Interface/bottom-bar.png"),
	        w:765,
	        h:72,
	        x:(centerObj.w-765)/2,
	        y:(centerObj.h-72),
	        lastDraw:true
	    });
	    var arr  = getAnimateArr("1x5","1");
	    centerObj.p=new HGAME.bulletA({
	        lastDraw:true,
	        imgArr:[
	            METHOD.createImg("img/bullet/cannon1.png"),
	            METHOD.createImg("img/bullet/cannon2.png"),
	            METHOD.createImg("img/bullet/cannon3.png"),
	            METHOD.createImg("img/bullet/cannon4.png"),
	            METHOD.createImg("img/bullet/cannon5.png"),
	            METHOD.createImg("img/bullet/cannon6.png"),
	            METHOD.createImg("img/bullet/cannon7.png")
	        ],
	        bulletImgArr:[
	            METHOD.createImg("img/bullet/bullet1.png"),
	            METHOD.createImg("img/bullet/bullet2.png"),
	            METHOD.createImg("img/bullet/bullet3.png"),
	            METHOD.createImg("img/bullet/bullet4.png"),
	            METHOD.createImg("img/bullet/bullet5.png"),
	            METHOD.createImg("img/bullet/bullet6.png"),
	            METHOD.createImg("img/bullet/bullet7.png")
	        ],
	        gridImgArr:[
	            METHOD.createImg("img/bullet/web1s.png"),
	            METHOD.createImg("img/bullet/web2s.png"),
	            METHOD.createImg("img/bullet/web3s.png"),
	            METHOD.createImg("img/bullet/web4s.png"),
	            METHOD.createImg("img/bullet/web5.png"),
	            METHOD.createImg("img/bullet/web6s.png"),
	            METHOD.createImg("img/bullet/web7s.png")
	        ],
	        changeImgArr:arr,
	        pt:centerObj.pt,
	        imgInfoTxt:"1x5"

	    });

	    METHOD.defineEx(centerObj,"num",localStorage.num?localStorage.num:1000,function(){
	        localStorage.num=centerObj.num;
	    });
	    centerObj.addRect={
	        w:44,
	        h:31,
	        y:646,
	        x:622,
	        downImg:METHOD.createImg(  "img/Interface/cannon_plus_down.png"),
	        noDownImg:METHOD.createImg( "img/Interface/cannon_plus.png"),
	        img:METHOD.createImg( "img/Interface/cannon_plus.png")
	    };
	    centerObj.noAddRect={
	        w:44,
	        h:31,
	        y:646,
	        x:442,
	        noDownImg:METHOD.createImg( "img/Interface/cannon_minus.png"),
	        downImg:METHOD.createImg("img/Interface/cannon_minus_down.png"),

	        img:METHOD.createImg( "img/Interface/cannon_minus.png")
	    };

	});

	var imgStartbg = METHOD.createImg( "img/Interface/startbg.jpg");
	function emptyFun(){
	    centerObj.fishArr= new Array();
	    centerObj.bulletArr=new Array();
	    centerObj.createFishArr=new Array();
	    centerObj.goldArr=new Array();
	    centerObj.animate.stop();
	    centerObj.animate02.stop();
	    centerObj.animate03.stop();
	    centerObj.maxBox.empty();
	}
	centerObj.startRect=  {
	    x:centerObj.w/2-200/2,y:centerObj.h/2-60/2+100,
	    w:200,
	    h:60
	};
	function initCj(num){


	    centerObj.num=localStorage.num?localStorage.num:1000;
	    centerObj.cj=num;
	    if(!cjData[centerObj.cj])return console.log("error:loaded error !!");
	    centerObj.start="loadeding";
	    emptyFun();
	    centerObj.maxBox.add(centerObj.pt);
	    centerObj.maxBox.add(centerObj.p);

	    centerObj.loedSource.loadedSource(cjData[centerObj.cj][0],function(){
	        //  var yInfo=getAnimateArr("1x8","0");
	        var i = 0;
	        for(;i<cjData[centerObj.cj][1].length;i++){
	            getCreateInfo( cjData[centerObj.cj][1][i]);
	            var a = new HGAME.fishStruct(cjData[centerObj.cj][1][i]);
	            centerObj.createFishArr.push(a);
	        }
	        var bg = new HGAME.Object2D({
	            img:METHOD.createImg(cjData[centerObj.cj][2]),
	            w:centerObj.w,
	            h:centerObj.h,
	            x:0,
	            y:0
	        });
	        centerObj.maxBox.add(bg);
	        centerObj.animate.run();
	        centerObj.animate02.run();
	        centerObj.animate03.run();
	        centerObj.start="begin";
	    });
	};
	function selctUI(txt,text){
	    emptyFun();
	    text=text||"";
	    var  Y=80;
	    centerObj.start="selecting";
	    txt.beginPath();
	    txt.clearRect(0,0,centerObj.w,centerObj.h);
	    txt.drawImage(imgStartbg,0,0);
	    txt.textBaseline="top";
	    txt.textAlign="left";
	    txt.fillStyle="#ffffff";
	    txt.font="normal normal 20px/24px arial";
	    txt.fillText("选择场景:"+text,10,Y);
	    txt.fillStyle="#ffff00";
	    txt.font="normal normal 16px/20px arial";
	    txt.fillText("您的分数:"+centerObj.num,10,Y-25);
	    Y=Y+24+10+20;
	    var x =8;
	    var y=Y;
	    var int =0;
	    for(var i = 0;i< centerObj.cjShowArr.length;i++){
	        var img=centerObj.cjShowArr[i].img;

	        txt.drawImage(img,0,0,img.width,img.height,x,y,centerObj.cjShowArr[i].w,centerObj.cjShowArr[i].h);
	        txt.fillStyle="rgba(0,0,0,0.8)";
	        txt.fillRect(x,y+centerObj.cjShowArr[i].h-80,centerObj.cjShowArr[i].w,80);
	        txt.font="normal normal 16px/20px arial";
	        txt.fillStyle="#ffffff";
	        txt.fillText(centerObj.cjShowArr[i].say,x+10,y+centerObj.cjShowArr[i].h+20-80);
	        txt.fillStyle="#ffff00";
	        txt.fillText("需求分数:"+centerObj.cjShowArr[i].needNum,x+10,y+centerObj.cjShowArr[i].h+10-40);
	        centerObj.cjShowArr[i].x=x;
	        centerObj.cjShowArr[i].y=y;
	        x=x+centerObj.cjShowArr[i].w+16;
	        if(int==3){
	            int=0;
	            x=8;
	            y=y+centerObj.cjShowArr[i].h+100;
	        }else{
	            int++;
	        }


	    }
	    txt.closePath();
	}
	function startUI(txt){
	    // emptyFun();
	    centerObj.start="loading";
	    var startRect =centerObj.startRect;
	    txt.beginPath();
	    txt.clearRect(0,0,centerObj.w,centerObj.h);
	    txt.drawImage(imgStartbg,0,0);
	    txt.drawImage(METHOD.createImg( "img/Interface/login.png"),centerObj.w/2-387/2,centerObj.h/2-287/2-80);
	    txt.fillStyle="#0994ff";
	    txt.shadowBlur=20;
	    txt.shadowColor="#098eff";
	    txt.fillRect(startRect.x,startRect.y,startRect.w,startRect.h);
	    txt.shadowBlur=0;
	    txt.textBaseline="middle";
	    txt.font="normal normal 20px/24px arial";
	    txt.textAlign="center";
	    txt.fillStyle="#ffffff";

	    txt.fillText("开始游戏",startRect.x+startRect.w/2,startRect.y+startRect.h/2);
	    console.log('startRect:',startRect,'centerObj:',centerObj)
	    txt.closePath();
	}

	centerObj.ele.appendChild(centerObj.canvas);
	var cTxt=centerObj.canvas.getContext("2d");
	centerObj.animate04.action=function(){
		centerObj.canvas.width=centerObj.w;
		centerObj.canvas.height=centerObj.h;
		var w=centerObj.canvas.width;
		var h=w/centerObj.w*centerObj.h;
		var x = 0,
		    y=(centerObj.canvas.height-h)/2;
		if(h>centerObj.canvas.height){
		    h=centerObj.canvas.height;
		    w=h/centerObj.h*centerObj.w;
		    y=0;
		    x=(centerObj.canvas.width-w)/2;
		}
		
		centerObj.canvas.w=w;
		centerObj.canvas.h=h;
		centerObj.canvas.x = x;
		centerObj.canvas.y=y;
		cTxt.beginPath();
		cTxt.clearRect(0,0,centerObj.canvas.width,centerObj.canvas.height);
		cTxt.fillStyle="#000000";
		cTxt.fillRect(0,0,centerObj.canvas.width,centerObj.canvas.height);
		// console.log('x',x,'y',y,'w',w,'h',h);

		cTxt.drawImage(centerObj.maxBox.dom,0,0,centerObj.w,centerObj.h,x,y,w,h);
		cTxt.closePath();
	}
	centerObj.animate04.run();

	function clickDomFun(p){
		if(centerObj.start=="loading"){
		    if(METHOD.inRect(p,centerObj.startRect)){
		        selctUI(centerObj.maxBox.txt);
		    }
		}
	}
	centerObj.canvas.addEventListener("click",function(e){
	    var p = {
	        x: e.offsetX-centerObj.canvas.x,
	        y: e.offsetY-centerObj.canvas.y
	    };
	    if(p.x<0|| e.y<0){
	        return
	    }
	    p.x= p.x*centerObj.w/centerObj.canvas.w;
	    p.y= p.y*centerObj.h/centerObj.canvas.h;
	    clickDomFun(p);

	},true);

	

	function getAnimateArr(imgInfo,ty){

	    imgInfo=imgInfo||"1x8";
	    var arr = new Array();
	    var arr02 = new Array();
	    function fun(num,w,h){
	        var i = 0;
	        if(num==0){
	            for(;i<h/2;i++){
	                arr.push({w:0,h:i});
	                arr02.push({w:0,h:h/2+i});
	            }
	        }else if(num==1){
	            for(i=0;i< h;i++){
	                arr.push({w:0,h:i});
	            }
	        }else if(num==2){
	            var a=h/3;
	            for(i=0;i< h;i++){
	                if(i>a*2-1){
	                    arr02.push({w:0,h:i});
	                }else{
	                    arr.push({w:0,h:i});
	                }
	            }
	        }else if(num==3&&h==10){
	            for(i=0;i< h;i++){
	                if(i>5){
	                    arr02.push({w:0,h:i});
	                }else{
	                    arr.push({w:0,h:i});
	                }
	            }
	        }else if(num==4&&h==15){
	            for(i=0;i< h;i++){
	                if(i>13){
	                    arr02.push({w:0,h:i});
	                }else{
	                    arr.push({w:0,h:i});
	                }
	            }
	        }else if(num==5&&h==33){
	            for(i=0;i< h;i++){
	                if(i>29){
	                    arr02.push({w:0,h:i});
	                }else{
	                    arr.push({w:0,h:i});
	                }
	            }
	        }
	    }
	    switch (imgInfo){
	        case "1x8":{
	            switch (ty){
	                case "0":{
	                    fun(0,1,8);
	                    break;
	                }
	            }
	            break;
	        }
	        case "1x12":{
	            switch (ty){
	                case "0":{
	                    fun(0,1,12);
	                    break;
	                }
	                case "2":{
	                    fun(2,1,12);
	                }
	            }
	            break;
	        }
	        case '1x10':{
	            switch (ty) {
	                case "0":{
	                    fun(0,1,10);
	                    break;
	                }
	                case "1":{
	                    fun(1,1,10);
	                    break;
	                }
	                case "3":{
	                    fun(3,1,10);
	                    break;
	                }
	            }
	            break;
	        }
	        case "1x15":{
	            switch (ty){
	                case "4":{
	                    fun(4,1,15);
	                }
	                    break;
	            }
	            break;
	        }
	        case "1x33":{
	            switch (ty){
	                case "5":{
	                    fun(5,1,33);
	                }
	            }
	            break;
	        }
	        case "1x5":{
	            switch (ty){
	                case "1":{
	                    fun(1,1,5);
	                    break;
	                }
	            }
	            break;
	        }
	    }
	    if(ty=='0'||ty=="2"||ty=="3"||ty=="4"||ty=="5"){
	        return {
	            a:arr,
	            b:arr02
	        }
	    }else if(ty=="1"){
	        return arr;
	    }

	}
	function getCreateInfo(O){
	    var yInfo=getAnimateArr(O.imgInfoAg, O.imgInfoAg02);
	    O.swimArr=yInfo.a;
	    O.deathArray=yInfo.b;
	}
})();